﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using Services;
using Contracts;


namespace Hosting
{
    partial class MyService : ServiceBase
    {
        ServiceHost host;
        public MyService()
        {
            InitializeComponent();
            host = new ServiceHost(typeof(CalculatorService));
        }

        protected override void OnStart(string[] args)
        {

            host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://127.0.0.1:9999/calculatorservice");

            if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            {

                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                behavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/calculatorservice/metadata");
                host.Description.Behaviors.Add(behavior);
            }
            host.Open();
        }

        protected override void OnStop()
        {
            host.Close();
        }
    }
}
